import java.util.Scanner;

/**
 * @author : niu niu
 * @version : 1.0.0
 * @date : 2022/10/17 8:15
 * //Fibonacci数列
 * //合法括号序列判断
 */
public class Day7 {
    //Fibonacci数列
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt(); //输入

        //algo
        int num1 = 0; //F[0]
        int num2 = 1; //F[1]

        int left = 0;
        int right = 0; //N左右的数
        while(true){
            int num3 = num1 + num2;
            num1 = num2;
            num2 = num3;
            if(num2< N){
                left = num2;
            }else {
                right = num2;
                break;
            }
        }
        int ret = N-left < right-N? N-left:right-N;
        System.out.println(ret);
    }

    //合法括号序列判断
    public static void main(String[] args) {
        String str = "()a()()";
        String str1 = "()(()()";
        System.out.println(chkParenthesis(str1, str.length()));
    }
    public static boolean chkParenthesis(String A, int n) {
        // write code here
        char[] strCh = A.toCharArray();
        int leftCount = 0;
        int rightCount = 0;
        for (int i = 0; i < n; i++) {
            if (strCh[i] == '('){
                leftCount++;
            }
            else if(strCh[i]==')')
            {
                rightCount++;
            }else {
                return false;
            }
            if (rightCount>leftCount){
                return  false;
            }
        }
        if (leftCount == rightCount){
            return true;
        }else {
            return false;
        }
    }
}
